/*
 *
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: OrderState.java
 *   @Date: 11/29/18 3:21 PM
 *   @Author: chenjun
 *   @Copyright（C）: 2018 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 *
 */

package io.bhex.sdk.account.bean.enums;

/**
 * 订单状态
 *
 * @author ppzhao
 */
public enum OrderState {
    /**
     * 委托单状态 A未成交 B部分成交 C全部成交 D已撤单
     */
    ORDER_STATE_A("A", "未成交"),
    ORDER_STATE_B("B", "部分成交"),
    ORDER_STATE_C("C", "全部成交"),
    ORDER_STATE_D("D", "已撤销"),
    /*1：正在申报
    2：无效
    3：部成部撤
    c：全部成交
    d：已撤销
    o：已报入
    p：部分成交
    s：系统撤销*/
    ORDER_STATE_SJS_1("1", "正在申报"),
    ORDER_STATE_SJS_2("2", "无效"),
    ORDER_STATE_SJS_3("3", "部分已成交"),
    ORDER_STATE_SJS_c("c", "全部成交"),
    ORDER_STATE_SJS_d("d", "已撤销"),
    ORDER_STATE_SJS_o("o", "已报入"),
    ORDER_STATE_SJS_p("p", "部分成交"),
    ORDER_STATE_SJS_s("s", "系统撤销");

    private String code;
    private String name;

    OrderState(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static OrderState findByCode(String code) {
        for (OrderState sCode : OrderState.values()) {
            if (sCode.getCode().equals(code)) {
                return sCode;
            }
        }
        return null;
    }


    public static boolean canRevert(String code) {
        OrderState state = findByCode(code);

        return state == ORDER_STATE_A || state == ORDER_STATE_B
                || state == ORDER_STATE_SJS_o || state == ORDER_STATE_SJS_p;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
